import { createStore } from 'vuex'
import { getMusicLyric } from '@/request/api/item'

export default createStore({
  state: {
    playList:[{
      al:{  // 给一个默认值
        id: 127008464,
        name: "最后的句号",
        pic: 109951165956423040,
        picUrl:"https://p1.music.126.net/teQ44sEFry607xd86Garbg==/109951165956423041.jpg",
        pic_str: "109951165956423041",
      },
      id:1842865092,// 歌曲id
      name: "最后的句号"
    }],
    playListIndex:0,//默认下标为0
    isbtnShow:true,// 播放状态
    detailShow:false, // 弹窗
    lyricList:{},     //歌词
    currentTime:0, //当前时间
    duration:0,// 歌曲总时长
  },
  getters: {
  },
  mutations: {
    updataisbtnShow:function(state,value){
      state.isbtnShow = value
    },
    updataPlayList:function(state,value){
      state.playList = value
      // console.log(state.playList);
    },
    updataPlayListIndex:function(state,value){
      state.playListIndex = value
    },
    updataDetailShow:function(state,){
      state.detailShow = !state.detailShow
    },
    updataLyricList:function(state,value){
      state.lyricList = value
    },
    updatacurrentTime:function(state,value){
      console.log(state.currentTime);
      state.currentTime = value
    },
    updateDuration:function(state,value){
      state.duration = value
    },
    pushPlayList:function(state,value){
      state.playList.push(value)
    }
  },
  actions: {
    getLyric:async function(ctx,value){
      let res = await getMusicLyric(value)
      console.log(res);
      ctx.commit("updataLyricList",res.data.lrc)
    }
  },
  modules: {
  }
})
